// main.ts
// 获取应用实例
// const app = getApp<IAppOption>()
import { apis } from '../../apis/apis'
import {  requestPromise } from '../../utils/requestPromise'
Component({
  
  data: {
    examList:<any>[],
    examCategoryInfo:{},
  },
  methods: {
    adLoad() {
      console.log('Banner 广告加载成功')
    },
    adError(err:any) {
      console.error('Banner 广告加载失败', err)
    },
    adClose() {
      console.log('Banner 广告关闭')
    },
    onShareAppMessage(){
      return {
        title:"快来看看你的MBTI",
        path:"/pages/main/main",
      }
    },
    onShareTimeline(){
      
    },
    // 事件处理函数
    doExam(event:any) {
      const id = event.currentTarget.dataset.id
      wx.navigateTo({
        url: '/pages/testing/testing?id='+id,
      })
    },
    getExamCategoryInfo(){
      let _th = this;
      requestPromise({
        url:apis.examCategoryInfo+"/1",
        method:"GET",
        data:{
        },
      }).then((res:any)=>{
        _th.setData({
          examCategoryInfo:res.data.data
        })
      })
    },
    getExamList(){
      let _th = this;
      requestPromise({
        url:apis.examList,
        method:"GET",
        data:{
          cid:'1',
        },
      }).then((res:any)=>{
        _th.setData({
          examList:res.data.data
        })
      })
    },
  },
  lifetimes: {
    attached() {
     this.getExamCategoryInfo();
     this.getExamList();
    }
  },
})
